package com.qf.day08.user.impl;

import com.qf.day08.user.service.UserMenuService;
import com.qf.day08.user.service.UserService;

import java.util.Scanner;

public class UserMenuServiceImpl implements UserMenuService {

    UserService userService=new UserServiceImpl();
    @Override
    public void show() {
        Scanner scanner = new Scanner(System.in);
        while (true){
            System.out.println("请输入数字选择功能:1.注册\t2.登录\t3.退出");
            int userMeneuNum=scanner.nextInt();
            switch (userMeneuNum){
                case 1:
                    System.out.println("欢迎来到注册功能");
                    System.out.println("请输入用户名");
                    String userName=scanner.next();
                    System.out.println("请输入密码");
                    String passWord=scanner.next();
                    boolean registerFlag=userService.register(userName,passWord);
                    if(registerFlag){
                        System.out.println("恭喜"+userName+"用户注册成功");
                    }else{
                        System.out.println("用户名为"+userName+"重复了,请重新注册");
                    }
                    break;
                case 2:
                    System.out.println("欢迎来到登录功能");
                    System.out.println("请输入用户名");
                    String loginUserName=scanner.next();
                    System.out.println("请输入密码");
                    String loginPassWord=scanner.next();
                    boolean loginFlag=userService.login(loginUserName,loginPassWord);
                    if(loginFlag){
                        System.out.println("恭喜"+loginUserName+"用户登录成功");
                    }else{
                        System.out.println("用户名或密码错误,请重新登录");
                    }
                    break;
                case 3:
                    System.out.println("再见");
                    return;
                default:
                    System.out.println("请输入正确功能号码");
                    break;
            }
        }
    }
}
